package com.lc202309;

/**
 * Description:
 *
 * @Create 2023/10/2 23:06
 * @Version 1.0
 */
public class Solution1790 {
    public boolean areAlmostEqual(String s1, String s2) {
        int length = s1.length();
        int num = 0;
        int index = -1;
        for (int i = 0; i < length; i++) {
            if (s1.charAt(i) == s2.charAt(i)) {
                continue;
            }
            num++;
            if (num > 2) {
                return false;
            }
            if (index == -1) {
                index = i;
                continue;
            }
            if (s1.charAt(i) != s2.charAt(index) || s1.charAt(index) != s2.charAt(i)) {
                return false;
            }
        }
        return num == 2 || num == 0;
    }
}
